<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | 王勇程 <laughskydragon@qq.com>                         |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\validate;

/**
 * 前端用户验证器
 */
class User extends ValidateBase
{
    
    // 验证规则
    protected $rule = [
        'openid'        => 'require|length:1,64',
        'unionid'       => 'length:0,64',
        'nickname'      => 'require|length:1,50',
        'avatar_url'    => 'length:0,255',
        'vip_level'     => 'integer|between:0,3',
        'invite_code'   => 'length:0,20|unique:user',
        'inviter_id'    => 'integer|egt:0',
        'total_earnings'=> 'float|egt:0',
        'available_amount' => 'float|egt:0',
        'total_points'  => 'integer|egt:0',
        'status'        => 'require|in:0,1',
    ];

    // 验证提示
    protected $message = [
        'openid.require'        => 'openid不能为空',
        'openid.length'         => 'openid长度不能超过64个字符',
        'unionid.length'        => 'unionid长度不能超过64个字符',
        'nickname.require'      => '用户昵称不能为空',
        'nickname.length'       => '用户昵称长度为1-50个字符',
        'avatar_url.length'     => '头像地址长度不能超过255个字符',
        'vip_level.integer'     => 'VIP等级必须为整数',
        'vip_level.between'     => 'VIP等级范围为0-3',
        'invite_code.length'    => '邀请码长度不能超过20个字符',
        'invite_code.unique'    => '邀请码已存在',
        'inviter_id.integer'    => '邀请人ID必须为整数',
        'inviter_id.egt'        => '邀请人ID不能为负数',
        'total_earnings.float'  => '累计收益必须为数字',
        'total_earnings.egt'    => '累计收益不能为负数',
        'available_amount.float'=> '可提现金额必须为数字',
        'available_amount.egt'  => '可提现金额不能为负数',
        'total_points.integer'  => '总积分必须为整数',
        'total_points.egt'      => '总积分不能为负数',
        'status.require'        => '用户状态不能为空',
        'status.in'             => '用户状态值不正确',
    ];

    // 应用场景
    protected $scene = [
        'add'    => ['nickname', 'openid', 'status'],
        'edit'   => ['nickname', 'status'],
        'wechat' => ['openid', 'nickname'],
        'vip'    => ['vip_level'],
        'points' => ['total_points'],
        'earnings' => ['total_earnings', 'available_amount'],
    ];
}